package com.orgcent.activities;

import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
/**
 * 美化TabHost,模拟“米聊”
 */
public class CustomTabActivity extends TabActivity {

	private TabHost tabhost;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.custom_tab_activity);
		
		tabhost = getTabHost();
		setIndicator(R.drawable.sms_btn_contact, R.string.tab_name_1, R.id.first);
		setIndicator(R.drawable.sms_btn_contact, R.string.tab_name_2, R.id.second);
		setIndicator(R.drawable.sms_btn_contact, R.string.tab_name_3, R.id.first);
		setIndicator(R.drawable.sms_btn_contact, R.string.tab_name_4, R.id.second);
	}

	private void setIndicator(int icon, int title, int view) {  
	      
	    View localView = LayoutInflater.from(this.tabhost.getContext()).inflate(R.layout.main_activity_tab, null);  
	    ((ImageView)localView.findViewById(R.id.main_activity_tab_image)).setBackgroundResource(icon);  
	    ((TextView)localView.findViewById(R.id.main_activity_tab_text)).setText(title);  
	      
	    String str = getResources().getString(title);  
	      
	    TabHost.TabSpec localTabSpec = tabhost.newTabSpec(str).setIndicator(localView).setContent(view);  
	    tabhost.addTab(localTabSpec);  
	      
	}  
}
